﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Experimental.GlobalIllumination.LinearColor
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using UnityEngine.Rendering;

#nullable disable
namespace UnityEngine.Experimental.GlobalIllumination
{
  /// <summary>
  ///   <para>Contains normalized linear color values for red, green, blue in the range of 0 to 1, and an additional intensity value.</para>
  /// </summary>
  public struct LinearColor
  {
    private float m_red;
    private float m_green;
    private float m_blue;
    private float m_intensity;

    /// <summary>
    ///   <para>The red color value in the range of 0.0 to 1.0.</para>
    /// </summary>
    public float red
    {
      get => this.m_red;
      set
      {
        this.m_red = (double) value >= 0.0 && (double) value <= 1.0 ? value : throw new ArgumentOutOfRangeException("Red color (" + value.ToString() + ") must be in range [0;1].");
      }
    }

    /// <summary>
    ///   <para>The green color value in the range of 0.0 to 1.0.</para>
    /// </summary>
    public float green
    {
      get => this.m_green;
      set
      {
        this.m_green = (double) value >= 0.0 && (double) value <= 1.0 ? value : throw new ArgumentOutOfRangeException("Green color (" + value.ToString() + ") must be in range [0;1].");
      }
    }

    /// <summary>
    ///   <para>The blue color value in the range of 0.0 to 1.0.</para>
    /// </summary>
    public float blue
    {
      get => this.m_blue;
      set
      {
        this.m_blue = (double) value >= 0.0 && (double) value <= 1.0 ? value : throw new ArgumentOutOfRangeException("Blue color (" + value.ToString() + ") must be in range [0;1].");
      }
    }

    /// <summary>
    ///   <para>The intensity value used to scale the red, green and blue values.</para>
    /// </summary>
    public float intensity
    {
      get => this.m_intensity;
      set
      {
        this.m_intensity = (double) value >= 0.0 ? value : throw new ArgumentOutOfRangeException("Intensity (" + value.ToString() + ") must be positive.");
      }
    }

    /// <summary>
    ///   <para>Converts a Light's color value to a normalized linear color value, automatically handling gamma conversion if necessary.</para>
    /// </summary>
    /// <param name="color">Light color.</param>
    /// <param name="intensity">Light intensity.</param>
    /// <returns>
    ///   <para>Returns the normalized linear color value.</para>
    /// </returns>
    public static LinearColor Convert(Color color, float intensity)
    {
      Color color1 = GraphicsSettings.lightsUseLinearIntensity ? color.linear.RGBMultiplied(intensity) : color.RGBMultiplied(intensity).linear;
      float maxColorComponent = color1.maxColorComponent;
      if ((double) color1.r < 0.0 || (double) color1.g < 0.0 || (double) color1.b < 0.0)
        throw new ArgumentOutOfRangeException("The input color to be converted must not contain negative values (red: " + color1.r.ToString() + ", green: " + color1.g.ToString() + ", blue: " + color1.b.ToString() + ").");
      if ((double) maxColorComponent <= 9.9999996826552254E-21)
        return LinearColor.Black();
      float num = 1f / color1.maxColorComponent;
      LinearColor linearColor;
      linearColor.m_red = color1.r * num;
      linearColor.m_green = color1.g * num;
      linearColor.m_blue = color1.b * num;
      linearColor.m_intensity = maxColorComponent;
      return linearColor;
    }

    /// <summary>
    ///   <para>Returns a black color.</para>
    /// </summary>
    /// <returns>
    ///   <para>Returns a black color.</para>
    /// </returns>
    public static LinearColor Black()
    {
      LinearColor linearColor;
      linearColor.m_red = linearColor.m_green = linearColor.m_blue = linearColor.m_intensity = 0.0f;
      return linearColor;
    }
  }
}
